package com.bitcola.security.activity.consumer;


import com.alibaba.druid.sql.dialect.h2.visitor.H2ASTVisitor;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bitcola.entity.ApplyLog;
import com.bitcola.security.activity.biz.*;
import com.bitcola.security.activity.feign.IDataServiceFeign;
import com.bitcola.security.activity.feign.IMeFeign;
import com.bitcola.security.activity.mapper.ColaUserMapper;
import com.bitcola.entity.ColaUserEntity;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;

import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

@Service
@Log4j2
public class UserConsumer   implements ApplicationRunner {



    @Autowired
    UserInviterBiz userInviterBiz;
    @Autowired
    ChargeBiz chargeBiz;

    @Autowired
    ApplyBiz applyBiz;
    @Autowired
    RedPacketBiz redPacketBiz;
    @Resource
    IDataServiceFeign dataServiceFeign;
    @Autowired
    BalanceChangeBiz balanceChangeBiz;
    @Autowired
    KycBiz kycBiz;

    @Autowired
    SignUpBiz signUpBiz;
    ExecutorService executorService = Executors.newFixedThreadPool(500);
    @Resource
    IMeFeign meFeign;
    @Resource
    ColaUserMapper userMapper;
    //用户kyc成功



    @Autowired
    StringRedisTemplate redisTemplate;




    @Autowired
    MiningBiz miningBiz;



    @Override
    public void run(ApplicationArguments args) throws Exception {
        executorService.submit(()->{
            while(true){
                ColaUserEntity userEntity=null;
                try {

//                    redisTemplate.opsForList().rightPush("user_active",JSONObject.toJSONString(map));
                    var value= redisTemplate.opsForList().rightPop("user_active");
                    userEntity=JSONObject.parseObject( value,ColaUserEntity.class);
                    if(userEntity!=null){
                        userInviterBiz.createNewInvitor(userEntity.getSysUserID(), userEntity.getInviter());
                    }else{
                        Thread.sleep(1000);
                    }
                }catch (Exception e){
                    e.printStackTrace();
                }

            }
        });
    }
}
